package 反射第一遍.demo12;

import java.lang.reflect.Field;

/**
 * @author wql
 * @version 1.0
 * @date 2022/10/27 14:28
 */

public class Test {
    public static void main(String[] args)throws Exception {
        Class<apple> aClass = apple.class;
        Field address = aClass.getDeclaredField("address");
        System.out.println("address = " + address);

        Field num = aClass.getDeclaredField("num");
        System.out.println("num = " + num);

        Field[] aClassDeclaredFields = aClass.getDeclaredFields();

        for (Field aClassDeclaredField : aClassDeclaredFields) {
            System.out.println("aClassDeclaredField = " + aClassDeclaredField);
        }

        Field address1 = aClass.getField("address");
        System.out.println("address1 = " + address1);

        Field name = aClass.getField("name");
        System.out.println("name = " + name);

        Field[] fields = aClass.getFields();
        for (Field field : fields) {
            System.out.println("field = " + field);
        }
    }
}
class vegetable{
    public  String name;
    private Integer price;

}
class apple extends vegetable{
    public String address;
    private Integer num;

    @Override
    public String toString() {
        return "apple{" +
                "address='" + address + '\'' +
                ", num=" + num +
                '}';
    }
}

